<template>
  <a-modal
      :width="800"
      title="选择委托人"
      :visible.sync="modalVisible"
      :confirmLoading="confirmLoading"
      @cancel="handleCancleDbSync"
      @ok="handleOkDbSync"
    >
      <j-select-user-by-dep v-model="multiUser" :multi="false" @change="userChange"></j-select-user-by-dep>
  </a-modal>
</template>
<script>
import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep'
import { entrustTask } from '@/api/task'
export default {
  name: 'taskEntrustModal',
  components: {
    JSelectUserByDep
  },
  data() {
    return {
      multiUser: '',
      multiUserName: '',
      modalVisible: false,
      confirmLoading: false,
      taskId: ''
    }
  },
  methods: {
    show(id) {
      this.taskId = id
      this.modalVisible = true
    },
    handleCancleDbSync() {
      this.modalVisible = false
    },
    userChange(data) {
      this.multiUserName = data
    },
    handleOkDbSync() {
      this.taskEntrust(this.multiUserName)
    },
    taskEntrust(data) {
      if (!data) {
        this.$message.error('请先选择委托人')
        return false
      }
      this.confirmLoading = true
      entrustTask({ taskId: this.taskId, userId: data }).then((res) => {
        if (res.success) {
          this.$message.success('流程委托成功')
          this.modalVisible = false
          this.$emit('ok')
        } else {
          this.$message.error(res.message)
        }
      }).finally(() => {
        setTimeout(() => {
          this.confirmLoading = false
        }, 60)
      })
    }
  }
}
</script>
<style lang="less">

</style>
